import { Column, Entity, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
import { CommonEntity } from 'src/common/entity/index.entity';
import { UserEntity } from '../../user/entities/user.entity';
import { ApiProperty } from '@nestjs/swagger';

@Entity('blog', {})
export class BlogEntity extends CommonEntity {
  @ApiProperty({ default: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' })
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ApiProperty({ default: '第一篇博客' })
  @Column('varchar', { length: 50, comment: '标题' })
  title: string;

  @ApiProperty({ default: '# 博客内容' })
  @Column('varchar', { length: 50, comment: '内容' })
  content: string;

  @ApiProperty({ default: ['demo'] })
  @Column('simple-array', {
    nullable: true,
    comment: '关键字',
  })
  keyword: [] | null;

  @ApiProperty({ default: '这是我的第一篇博客' })
  @Column('varchar', { length: 50, nullable: true, comment: '描述' })
  describe: string | null;

  @ApiProperty({ default: 'https://example.png' })
  @Column('varchar', { length: 50, nullable: true, comment: '预览图' })
  image: string | null;

  @Column('integer', { comment: '字数' })
  length: number;

  @Column('integer', { default: 0, comment: '访问次数' })
  visited: number;

  @ApiProperty({
    type: () => UserEntity,
    default: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
  })
  @ManyToOne(() => UserEntity, (user) => user.blogs)
  user: UserEntity;
}
